- main_toolbar do |t|
  = t.edit resource

= main_state_bar(resource)

= main_informations attachment: true do
  = attributes_list do |l|
    -# l.attribute :name
    - l.attribute :amount, currency: true
    -# l.attribute :state
    - l.attribute :journal_entry, url: true

    - l.attribute :loan_account, url: true
    - l.attribute :interest_account, url: true
    - l.attribute :insurance_account, url: true
    - l.attribute :accountable_repayments_started_on
    - l.attribute :initial_releasing_amount

    - l.attribute :use_bank_guarantee
    - if resource.use_bank_guarantee
      - l.attribute :bank_guarantee_account, url: true
      - l.attribute :bank_guarantee_amount

= cobbles do |c|
  - c.cobble :expenses do
    :ruby
      series = []
      data = [:base_amount, :interest_amount, :insurance_amount].collect do |info|
        [LoanRepayment.human_attribute_name(info), resource.repayments.sum(info).to_s.to_f ]
      end
      series << {name: :amounts, data: data}
    = pie_highcharts(series)
  - c.cobble :repayments do
    = cobble_list :repayments
  - c.cobble :repayments_graph do
    :ruby
      series = []
      interests = []
      interests_amount = 0
      resource.repayments.collect do |r|
        interests_amount += r.interest_amount
        interests << interests_amount.to_f
      end
      [:base_amount, :interest_amount, :insurance_amount].reverse.each do |info|
        series << {name: LoanRepayment.human_attribute_name(info), data: resource.repayments.pluck(info).map(&:to_f) }
      end
      series << {name: Loan.human_attribute_name(:remaining_amount), data: resource.repayments.pluck(:remaining_amount).map(&:to_f), type: 'line', marker: {enabled: false}, y_axis: 1}
    = area_highcharts(series, legend: true, y_axis: [{title: { text: Loan.human_attribute_name(:repayments)}, min: 0}, {title: { text: Loan.human_attribute_name(:remaining_amount)}, min: 0, opposite: true}], plot_options: {area: {stacking: 'normal', marker: {enabled: false}}})
